package zhaixf.fx.servlet;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import zhaixf.fx.DAO.RecordDAO;
import zhaixf.fx.DAO.TroubleDAO;
import zhaixf.fx.been.Tool;
import zhaixf.fx.service.ToolService;



@Controller
@RequestMapping("/mobel")
public class MobelController {

    @Autowired
    private ToolService toolService;
    @Autowired
    private TroubleDAO troubleDAO;
    @Autowired
    private RecordDAO recordDAO;

    @RequestMapping("/main")
    public String index(String id, Model model){
        model.addAttribute("status", toolService.getToolStatusById(id));
        model.addAttribute("id", id);
        return "mobel";
    }

    @RequestMapping("query")
    public String query(String id, Model model){
        model.addAttribute("tool", toolService.getToolById(id));
        return "query";
    }

    @RequestMapping("/record")
    public String record(String id, Model model){
        model.addAttribute("id", id);
        model.addAttribute("records", recordDAO.getRecordsByToolId(id));
        return "record";
    }


    @RequestMapping(value = "/baoxiu",method = RequestMethod.GET)
    public String baoxiuGet(String id, Model model){
        //获取version查询故障列表
        String version = id.split("_")[0];

        model.addAttribute("id", id);
        model.addAttribute("version", version);
        model.addAttribute("troubleList", troubleDAO.queryByVersion(version));
        return "baoxiu";
    }

    @RequestMapping(value = "/baoxiu",method = RequestMethod.POST)
    public String baoxiuPost(Tool tool, String pass, String bz, Model model){
        model.addAttribute("result", toolService.baoxiu(tool, pass, bz));
        return "result";
    }

    @RequestMapping(value = "/weixiu", method = RequestMethod.GET)
    public String weixiuGet(String id, Model model){
        model.addAttribute("tool", toolService.getToolById(id));
        return "weixiu";
    }

    @RequestMapping(value = "/weixiu", method = RequestMethod.POST)
    public String weixiuPost(Tool tool, String pass, String bz, Model model){
        model.addAttribute("result", toolService.weixiu(tool, pass, bz));
        return "result";
    }

    @RequestMapping("readme")
    public String readme(String version, Model model){
        model.addAttribute("version", version);
        return "sms/"+version;
    }
}
